package com.yztc.ui.classifydetail;

import android.util.Log;

import com.yztc.bean.classifydetail.ClassifyDetailBean;
import com.yztc.bean.classifydetail.ClassifyDetailHeaderBean;
import com.yztc.http.RetrofitService;
import com.yztc.utils.HttpHelper;

import java.util.Map;

import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by MengLingzhang on 2016/10/10.
 */
public class ClassifyDetailModle implements ClassifyDetailContract.Modle{

    @Override
    public void getVerticalClassifyDetailBean(String baseUrl, Map<String, String> map, final ClassifyDetailContract.OnLoadListener loadListener) {
        Observable observable=(Observable) HttpHelper
                .getInstance()
                .getRetrofit(baseUrl)
                .create(RetrofitService.class)
                .getClassifyDetailBean(map);
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ClassifyDetailBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.i("tag","++++++++++++++++++++++++++++++++++++++233");
                        loadListener.onFailure(e);
                    }

                    @Override
                    public void onNext(ClassifyDetailBean classifyDetailBean) {
                        Log.i("tag","++++++++++++++++++++++++++++"+classifyDetailBean.toString());
                        loadListener.onSuccess(classifyDetailBean);
                        Log.i("tag","-------------------------------------"+classifyDetailBean.toString());
                    }

                });
    }

    @Override
    public void getVerticalClassifyDetailHeaderBean(String baseUrl, int id, final ClassifyDetailContract.OnLoadListenerHeader loadListenerHeader) {

        Observable observable=(Observable)HttpHelper
                .getInstance()
                .getRetrofit(baseUrl)
                .create(RetrofitService.class)
                .getClassifyDetailHeaderBean(id);
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ClassifyDetailHeaderBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.i("tag","++++++++++++++++++++++++++++++++++++++ddddd");
                        loadListenerHeader.onFailure(e);
                    }

                    @Override
                    public void onNext(ClassifyDetailHeaderBean classifyDetailHeaderBean) {
                        Log.i("tag","++++++++++++++++++++++++++++++++++++++classifyDetailHeaderBean");
                        loadListenerHeader.onSuccess(classifyDetailHeaderBean);
                    }
                });
    }
}
